package org.example;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/8/23
 * Time: 11:08
 *///TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class Solution {
    public int findPeakElement(int[] nums) {
        if (nums.length == 1 || nums[0] > nums[1]) {
            return 0;
        }
        if (nums[nums.length - 1] > nums[nums.length - 2]) {
            return nums.length - 1;
        }
        int left = 0, right = nums.length - 1,mid = right / 2;
        while (left < right){
            if (nums[mid] <  nums[mid + 1]){
                left = mid + 1;
            }
            if (nums[mid] > nums[mid + 1]){
                right = mid;
            }
            mid = left +  (right - left) / 2;
        }
        return left;
    }
    public static void main(String[] args) {
        Solution s = new Solution();
        int peakElement = s.findPeakElement(new int[]{1, 2, 1, 3, 5, 6, 4});
        System.out.println(peakElement);
    }
}